package com.backend.service.impl;

import com.backend.entity.entity.Devices;
import com.backend.entity.entity.Users;
import com.backend.entity.entity.WorkOrders;
import com.backend.mapper.AdminMapper;
import com.backend.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * 作者:xuSen
 * 日期2025/7/20 11:03
 */
@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public List<Users> getAllUsers() {
        return adminMapper.selectAllUsers();
    }

    @Override
    public boolean deleteUserByUsername(String username) {
        int rows = adminMapper.deleteUserByUsername(username);
        return rows > 0;
    }

    @Override
    public List<Users> getUserByUsername(String username) {
        return adminMapper.selectUserByUsername(username);
    }

    @Override
    public List<WorkOrders> getAllOrders() {
        return adminMapper.selectAllOrders();
    }

    @Override
    public boolean deleteOrderById(Integer orderId) {
        int rows = adminMapper.deleteOrderById(orderId);
        return rows > 0;
    }

    @Override
    public List<WorkOrders> getOrdersByDeviceCode(String deviceCode) {
        return adminMapper.selectOrdersByDeviceCode(deviceCode);
    }

    @Override
    public boolean updateOrderStatus(Integer orderId, Integer status, String deviceCode, Integer repairmanId) {
        int rows = adminMapper.updateOrderStatus(orderId, status, deviceCode, repairmanId);
        return rows > 0;
    }

    @Override
    public Devices addDevice(Devices device) {
        adminMapper.insertDevice(device);
        return device;
    }

    @Override
    public List<Devices> getAllDevices() {
        return adminMapper.selectAllDevices();
    }

    @Override
    public boolean deleteDeviceById(Integer deviceId) {
        int rows = adminMapper.deleteDeviceById(deviceId);
        return rows > 0;
    }

    @Override
    public Devices updateDevice(Devices device) {
        adminMapper.updateDeviceInfo(device);
        return device;
    }

    @Override
    public Devices getDeviceByCode(String deviceCode) {
        return adminMapper.selectDeviceByCode(deviceCode);
    }
}
